﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

namespace Program10
{
    /// <summary>
    /// 加密类
    /// </summary>
    public class Encryption
    {
        public static string GetMd5(string str)
        {
            var md5 = MD5.Create();
            //将字符转换成二进制组
            var bitArray = Encoding.GetEncoding("UTF-8").GetBytes(str);
            //进行加密
            var md5BitArray = md5.ComputeHash(bitArray);

            var encryptStr = "";
            for(var i = 0; i < md5BitArray.Length; i++)
            {
                encryptStr += md5BitArray[i].ToString("x2");
            }
            md5.Clear();
            return encryptStr;
        }
        public static string GetSHA(string str)
        {
            var sha = SHA512.Create();
            //将字符转换成二进制组
            var bitArray = Encoding.GetEncoding("UTF-8").GetBytes(str);
            //进行加密
            var md5BitArray = sha.ComputeHash(bitArray);

            var encryptStr = "";
            for (var i = 0; i < md5BitArray.Length; i++)
            {
                encryptStr += md5BitArray[i].ToString("x2");
            }
            sha.Clear();
            return encryptStr;
        }
    }
}
